#ifndef __Logger_H__
#define __Logger_H__

#include <iostream>
#include <sstream>
#include <string>
#include <log4cpp/Category.hh>
#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/FileAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Priority.hh>

using std::string;
using std::ostream;
using std::ostringstream;
using std::cout;

class Mylogger {
public:
    
private:
    Mylogger() = default;
    Mylogger(const string &filename, const string &fileAppenderName, ostream &oslog, const string &osAppenderName) {
        _cat.setPriority(log4cpp::Priority::DEBUG);
        
        log4cpp::OstreamAppender *osAppender = new log4cpp::OstreamAppender(osAppenderName, &oslog);
        log4cpp::PatternLayout *pOstream = new log4cpp::PatternLayout();
        pOstream->setConversionPattern("%d{%H:%M:%S}:%c :%m%n");


        log4cpp::FileAppender *fileAppender = new log4cpp::FileAppender(fileAppenderName, filename);
        log4cpp::PatternLayout *pFile = new log4cpp::PatternLayout();
        pFile->setConversionPattern("%d{%H:%M:%S}:%c :%m%n");
        
        osAppender->setLayout(pOstream);
        fileAppender->setLayout(pFile);

        _cat.addAppender(osAppender);
        _cat.addAppender(fileAppender);
    }
private:
    //使用getRoot()得到根category;
    log4cpp::Category &_cat = log4cpp::Category::getRoot();
};





#endif
